package com.prestamomo.vil.ppa.pmvilmedium;

import com.prestamomo.vil.ppa.pmvilapi.PmvilSerConfig;
import com.prestamomo.vil.ppa.pmvilmedium.pmvilarm.pmlocation.PmvilOpenLocationMd;

import java.util.List;

/**
 * 创建日期：2022/12/27
 * 文件名称：CheckLocationUtil
 * 文件描述：
 */
public class CheckLocationUtil {

    public static boolean checkLoca(List<PmvilSerConfig.ExtInfoPmlJSON.LocationBean> locationBeans){

        for (int i = 0;i<locationBeans.size();i++){
            if (Double.parseDouble(locationBeans.get(i).getR()) > getDistance(PmvilOpenLocationMd.locationPmvilLat,PmvilOpenLocationMd.locationPmvilLot,
                    Double.parseDouble(locationBeans.get(i).getLat()),Double.parseDouble(locationBeans.get(i).getLng()))){
                return true;
            }
        }
        return false;
    }

    /**
     * 计算两点距离
     */
    private static final double EARTH_RADIUS = 6378137.0;
    public static double getDistance(double lat_a, double lng_a, double lat_b, double lng_b) {
        double radLat1 = (lat_a * Math.PI / 180.0);
        double radLat2 = (lat_b * Math.PI / 180.0);
        double a = radLat1 - radLat2;
        double b = (lng_a - lng_b) * Math.PI / 180.0;
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radLat1) * Math.cos(radLat2)
                * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }
}
